Ubuntu 16.04
Sponsored Link

OpenStack Queens : Add VM-Images
2018/03/13
 
Add Virtual Machine images in Glance.
[1]
Install KVM HyperVisor on Compute Host, refer to here.
It's unnecessarry to set Bridge networking on the section [3] of the link.
[2] For example, Create a Virtual Machine image of ubuntu 16.04.
# create a directory for disk image

root@dlp ~(keystone)#
mkdir -p /var/kvm/images
# create a disk image

root@dlp ~(keystone)#
qemu-img create -f qcow2 /var/kvm/images/ubuntu1604.img 10G
# install

root@dlp ~(keystone)#
virt-install \
--name ubuntu1604 \
--ram 2048 \
--disk path=/var/kvm/images/ubuntu1604.img,format=qcow2 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu16.04 \
--network network=default \
--graphics none \
--console pty,target_type=serial \
--location 'http://ftp.riken.go.jp/Linux/ubuntu/dists/xenial/main/installer-amd64/' \
--extra-args 'console=ttyS0,115200n8 serial'
Starting install...    
# installation starts
# after finishing installation, back to KVM Host and shutdown VM

root@dlp ~(keystone)#
virsh shutdown ubuntu1604
# mount the disk image of the VM

root@dlp ~(keystone)#
guestmount -d ubuntu1604 -i /mnt
# enable getty@ttyS0.service

root@dlp ~(keystone)#
ln -s /mnt/lib/systemd/system/getty@.service /mnt/etc/systemd/system/getty.target.wants/getty@ttyS0.service

# unmount and start

root@dlp ~(keystone)#
umount /mnt

root@dlp ~(keystone)#
virsh start ubuntu1604 --console
# configure some settings for openstack instance on VM

root@ubuntu:~#
apt-get -y install ssh cloud-init linux-virtual pollinate software-properties-common

root@ubuntu:~#
add-apt-repository cloud-archive:queens

root@ubuntu:~#
apt-get update

root@ubuntu:~#
vi /etc/default/grub
# line 11: change like follows

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="
console=tty1 console=ttyS0
"
GRUB_CMDLINE_LINUX=""
# line 35,36: comment out

#
GRUB_TERMINAL=serial
#
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stopp=1"
root@ubuntu:~#
update-grub
root@ubuntu:~#
vi /etc/cloud/cloud.cfg
# near line 13: add (if you'd like to allow SSH password authentication to login)

ssh_pwauth: true
# line 91: change (if you'd like to allow [ubuntu] user's SSH password auth)

default_user:
    name: ubuntu
    lock_passwd:
False
root@ubuntu:~#
vi /etc/network/interfaces
# comment out except loopback interface

# The primary network interface
#
auto ens2
#
iface ens2 inet dhcp
root@ubuntu:~#
systemctl enable serial-getty@ttyS0.service
# shutdown to finish settings

root@ubuntu:~#
shutdown -h now
[3] Add the virtual machine image to Glance.
root@dlp ~(keystone)#
openstack image create "Ubuntu1604" --file /var/kvm/images/ubuntu1604.img --disk-format qcow2 --container-format bare --public

+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | c6ec8738be2fc6a7bfa893c4e45024a6                     |
| container_format | bare                                                 |
| created_at       | 2018-03-15T02:22:41Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/217a694d-e526-4921-a018-6b1e6874ef44/file |
| id               | 217a694d-e526-4921-a018-6b1e6874ef44                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | Ubuntu1604                                           |
| owner            | 1ab4e37f25d14d4d8e8f5745c53bc885                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 2676490240                                           |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2018-03-15T02:22:56Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

root@dlp ~(keystone)#
openstack image list

+--------------------------------------+------------+--------+
| ID                                   | Name       | Status |
+--------------------------------------+------------+--------+
| 217a694d-e526-4921-a018-6b1e6874ef44 | Ubuntu1604 | active |
+--------------------------------------+------------+--------+
[4] By the way, if you got an image from internet, it's OK to simply add it like follows.
root@dlp ~(keystone)#
wget http://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P /var/kvm/images
root@dlp ~(keystone)#
openstack image create "Ubuntu1604" --file /var/kvm/images/ubuntu-16.04-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --public

+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | fc5ad26274fcc42cfa32d97308613432                     |
| container_format | bare                                                 |
| created_at       | 2017-02-24T01:44:21Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/3113fc28-fa1f-4221-909e-a4fc5bdb8d6a/file |
| id               | 3113fc28-fa1f-4221-909e-a4fc5bdb8d6a                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | Ubuntu1604                                           |
| owner            | 3424019a88f34894b22058d6e15a8d35                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 324141056                                            |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2017-02-24T01:44:23Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+
 
Tweet